from upload_common import read_data_from_stdin
from upload_common import data_is_http_link
from upload_common import handle_binary_data
from upload_common import write_data_to_stdout

data = read_data_from_stdin()
if data_is_http_link(data):
    write_data_to_stdout(data)
else:
    url = ""
    try:
        url = data.rstrip().decode("utf-8")
    except Exception as e:
        write_data_to_stdout(data)

    if url.startswith("file:///"):
        url = url.replace("file:///", "")
        try:
            with open(url, "rb") as file:
                write_data_to_stdout(file.read())
        except Exception as e:
            write_data_to_stdout(data)
    else: # 不以'file:///'开头则不是本handler处理的东西
        write_data_to_stdout(data)
